/*
 * Copy.java
 *

 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package beans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import util.ConnectionManager;
import util.Utilities;

/**
 *
 * @author HOME
 */
public class Copy {
    public static void main(String[] args) {
        Connection con = null;
        ResultSet rs = null;
        Statement stmt = null;
        int itemID = 0;
        try {
            con = ConnectionManager.connect();
            String query = "SELECT * From oldmodel";
            stmt = con.createStatement();
            rs = stmt.executeQuery(query);
            while(rs.next()) {
                
                con = ConnectionManager.connect();
                
                PreparedStatement update = con.prepareStatement("insert into model (  name, type, company, scale, price, description, imageURL, quantity3, distributionDate) values (  ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                
                ResultSetMetaData md = rs.getMetaData();
                
              
                for (int i = 1; i < 10; i++) {                    
                    update.setString(i, rs.getString(i+1));
                }
                update.executeUpdate();
            }
            rs.close();
            con.close();
        }catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //Utilities.close(rs, stmt, con);
        }
    }
}
